package com.zcily.utils.excel;

import java.text.Format;
import java.text.SimpleDateFormat;

public enum ExcelFormatPattern {
    NONE(""),
    DATE("yyyy-MM-dd"),
    DATETIME("yyyy-MM-dd HH:mm:ss"),
    ;

    private String style;

    ExcelFormatPattern(String style) {
        this.style = style;
    }

    public String getStyle() {
        return style;
    }

    public static String format(ExcelFormatPattern pattern, Object source) {
        String value = null;
        switch (pattern) {
            case NONE:
                value = "";
                break;
            case DATE:
            case DATETIME:
                value = new SimpleDateFormat(pattern.getStyle()).format(source);
                break;
        }
        return value;
    }

    public static Format getFormat(ExcelFormatPattern pattern) {
        Format format = null;
        switch (pattern) {
            case DATE:
            case DATETIME:
                format = new SimpleDateFormat(pattern.getStyle());
                break;
        }
        return format;
    }
}
